package com.ebelter.myehc.ui.fragments;


import android.os.Bundle;
import android.widget.TextView;
import com.ebelter.btcomlib.bases.fragment.BaseFragment;
import com.ebelter.btcomlib.models.bluetooth.products.bpm.BpmManager;
import com.ebelter.btcomlib.models.bluetooth.products.bpm.bean.BpmMesureResult;
import com.ebelter.btcomlib.utils.ViewUtils;
import com.ebelter.btcomlib.views.LevelColorView2;
import com.ebelter.myehc.R;
import com.ebelter.myehc.ui.view.CombinView5;
import com.ebelter.myehc.utils.EHCCommonUtils;
import com.ebelter.myehc.utils.ViewUtilsEHC;


/**
 * 血压计
 */

public class BPM_Fragment extends BaseFragment {
    public static final String TAG = "BPM_Fragment";
    LevelColorView2 bpm_lcv;
    CombinView5 cb5_bpm1;
    CombinView5 cb5_bpm2;
    CombinView5 cb5_bpm3;

    private TextView activityTopTittleTv;

    public void setActivityTopTittleTv(TextView activityTopTittleTv) {
        this.activityTopTittleTv = activityTopTittleTv;
    }
    @Override
    protected int setLayoutResouceId() {
        return R.layout.fragment_bpm;
    }
    @Override
    protected void initView() {
        super.initView();

        FV();
    }

   // int level;
    private void FV() {
        bpm_lcv=mRootView.findViewById(R.id.bpm_lcv);

        bpm_lcv.setLevel(-1);
        cb5_bpm1=mRootView.findViewById(R.id.cb5_bpm1);
        cb5_bpm2=mRootView.findViewById(R.id.cb5_bpm2);
        cb5_bpm3=mRootView.findViewById(R.id.cb5_bpm3);
    }


    @Override
    protected void initData(Bundle arguments) {
        super.initData(arguments);
        ViewUtilsEHC.setCb5Title2(cb5_bpm1,N);
        ViewUtilsEHC.setCb5Title2(cb5_bpm2,N);
        ViewUtilsEHC.setCb5Title2(cb5_bpm3,N);
    }

    public void setBPM_dynamicSystolicPressure(int value) {
        if (cb5_bpm2!=null)cb5_bpm2.setTitle2(value+"");
    }

    public void setBpmMesureResult(BpmMesureResult mesureResult) {
        if (cb5_bpm1!=null)cb5_bpm1.setTitle2(mesureResult.diastolicPressure+"");
        if (cb5_bpm2!=null)cb5_bpm2.setTitle2(mesureResult.systolicPressure+"");
        if (cb5_bpm3!=null)cb5_bpm3.setTitle2(mesureResult.pulse+"");

        String toptitle=BpmManager.getMesureResultDesc(mesureResult.systolicPressure,mesureResult.diastolicPressure);
//        ViewUtils.setTextViewStr(activityTopTittleTv,toptitle);
//        if (toptitle.length()>25){
//            ViewUtils.setTextSize(activityTopTittleTv,17);
//        }else {
//            ViewUtils.setTextSize(activityTopTittleTv,20);
//        }

        EHCCommonUtils.setTextViewStrAutoDisplay(activityTopTittleTv,toptitle,25,17,20);



        ViewUtils.displayView(bpm_lcv);
        if (bpm_lcv!=null)bpm_lcv.setLevel(BpmManager.getMesureResultLevel(mesureResult.systolicPressure,mesureResult.diastolicPressure));
    }
}
